package com.fengye.newscenter.controller;

import com.fengye.api.feign.clients.UserCenterClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author fengyexjtu@126.com
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/news")
public class NewsController {
    private static final Logger logger = LoggerFactory.getLogger(NewsController.class);
    @Value("${user.name}")
    private String name;
    
    @Autowired
    private UserCenterClient userCenterClient;

    @Autowired
    private RestTemplate restTemplate;
    
    @GetMapping("/hello")
    public String hello() {
        System.out.println("name = " + name);
        logger.info("name = {}", name);
        return name;
    }

    @GetMapping("/hello/restTemplate")
    public String helloFromRestTemplate() {
        System.out.println("name = " + name);
        logger.info("name = {}", name);
        return restTemplate.getForEntity("http://usercenter/user/hello", String.class).getBody();
    }
    
    @GetMapping("/hello/usercenter")
    public String helloFromUsercenter() {
        return userCenterClient.getUsername();
    }
}
